package com.caicai.ssm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import com.caicai.ssm.entity.Goods;
import com.caicai.ssm.entity.User;
import com.caicai.ssm.mapper.UserMapper;
import com.caicai.ssm.service.LoginService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class LoginServiceImpl implements LoginService{
	@Resource
	private UserMapper dao;
	@Override
	public ModelAndView isLogin(String username,String password) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("redirect:/index.jsp");
		User user = dao.findByUsername(username);
		if(user==null){//判断输入的用户名不存在的情况
			return mv;
		}
		if(user.getPassword().equals(password)){
			mv.addObject("username", username);
			mv.setViewName("/success");//设置逻辑视图
			return mv;
		}
		return mv;
	}
	@Override
	public List<Goods> findAllGoods() {
		List<Goods> list = dao.findAllGoods();
		return list;
	}
	@Override
	public PageInfo<Goods> findAllGoodsPage(int currentPage, int pageSize) {
		 	Page<Goods> page = PageHelper.startPage(currentPage, pageSize);
	        dao.findAllGoods();
	        PageInfo<Goods> pageInfo = page.toPageInfo();
	        return pageInfo;
	}
	
}
